<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 								
	<head> 							
		<%@ include file="../jslib/jquerylib.jsp" %>
	    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
        <link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
        <link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
        <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/jquery.ztree.core-3.4.js"></script>
        <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
	       <!-- 删除结果信息返回 -->
	    	<c:if test="${requestScope.message!=null}">
				<script type="text/javascript">
	  	 		     alert('<c:out value="${requestScope.message}"></c:out>');
	  	 		     window.close();
	  			</script>
	        </c:if>
	 
	<script type="text/javascript">
	$(document).ready(function(){
	
			
				//高级搜索需要的js
				buttonStatus=1;
				$("#flip").click(function(){
					if(buttonStatus==1){
						$("#panel").slideToggle("slow");
						$("#flip").toggleClass("btnStatus2");
						buttonStatus=1;
					}
					else{
						$("#panel").slideUp("slow");
						$("#flip").toggleClass("btnStatus2");
					}
			 });
				 //高级搜索结束
	
					$("#gridTable").jqGrid({
						url:'<%=request.getContextPath() %>/weituodan!queryGuzhangKuList.action',
						datatype: "json",
						height: 450,
						width: 710, 
						autowidth: true, 
						colNames:['主键','车型','子系统','零部件','故障名称','故障等级','里程','故障图片','任务识别号','故障发生时间','故障描述','TASKID','记录人'],
						colModel:[{name:'ID',index:'ID',key:true,hidden:true, width:100,hidedlg:true},
					          {name:'CHXINGNAME',index:'CHXINGNAME', width:100},
					          {name:'XITONGNAME',index:'XITONGNAME', width:180},
					          {name:'LINGBUJIANNAME',index:'LINGBUJIANNAME', width:180},
					          {name:'GUZHANGPATTERNNAME',index:'GUZHANGPATTERNNAME', width:120},
					          {name:'GUZHANG_DENGJI',index:'GUZHANG_DENGJI', width:80},
					          {name:'LICHENG',index:'LICHENG', width:80},
					          {name:'GUZHANGPIC',index:'GUZHANGPIC', width:80},
					          {name:'SHIBIEHAO',index:'SHIBIEHAO', width:100},
					          {name:'GUZHANGFASHENGTIME',index:'GUZHANGFASHENGTIME', width:100},
					          {name:'GUZHANG_MIAOSHU',index:'GUZHANG_MIAOSHU', width:180},
					          {name:'TASKID',index:'TASKID', width:180,hidden:true},
					          {name:'ADDUSER',index:'ADDUSER', width:100}
					],
					shrinkToFit:false,
					sortname:'id',
					sortorder:'desc',
					viewrecords:true,
					multiselect: true, // 是否显示复选框
					multiboxonly : true, 
					//gridview: true,  //提升速度
					rownumbers: true,//显示行号
					rownumWidth: 30, //行号的宽度
					rowNum:15,
					rowList:[15,20,50,200,500],
					toolbar: [false,"top"],
					loadComplete: function() {
						var ids = jQuery("#gridTable").getDataIDs();
				        if(ids.length<20){
				        	 jQuery("#gridTable").jqGrid('setGridHeight',390); 
				        	 parent.document.getElementById("mainframe").height=670; 
				        }else{
				        	 jQuery("#gridTable").jqGrid('setGridHeight',ids.length*24); 
				        	 parent.document.getElementById("mainframe").height=ids.length*24+410; 
				        }
				        var n = jQuery("#gridTable").getGridParam('records'); 
					},
					jsonReader: {
						root:"rows",		// 数据行（默认为：rows）
						page: "page",  	// 当前页
						total: "total",  // 总页数
						records: "records",  // 总记录数
						repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
					},
					prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
					pager:"#gridPager",
					caption: "故障库列表"
			});
			    $("#consoleDlg").dialog({
			        autoOpen: false,      
			        modal: true,    // 设置对话框为模态（modal）对话框  
			        resizable: true,      
			        width: 700,  
			        buttons: {  // 为对话框添加按钮  
			            "关闭": function() {$("#consoleDlg").dialog("close")}
			        }  
			    }); 
				 jQuery("#gridTable").jqGrid('navGrid','#gridPager',{add:false,edit:false,del:false,search:false,refresh:false});
					jQuery("#gridTable").jqGrid('navButtonAdd','#gridPager',
								{ 	
								caption: "",                          
								onClickButton : function (){                               
								jQuery("#gridTable").jqGrid('setColumns');                           
								}
					}); 
								doResize(); 
							//	afterCompleteFunction();										
	}); 
	
	//执行大小
	function doResize() { 
		var ss = getPageSize(); 
		//alert(ss.WinH);
		
			 $("#gridTable").jqGrid('setGridHeight', ss.WinH-245);
			 $("#gridTable").jqGrid('setGridWidth', ss.WinW-30); 
			} 
	
	 //查看
		function viewGuzhang(){
			var ids= $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
			if (!ids) {
			    alert("请先选择记录!");  
			    return false;  
			}
			if(ids.indexOf(",")!=-1){
				  alert("只能选择一条记录!");  
			        return false; 
			}
			var row = jQuery("#gridTable").jqGrid('getRowData',ids);//获取选中行.
			var id = row.ID;//获取选中行的id属性
			var toUrl = '<%=request.getContextPath() %>/weituodan!viewGuzhang.action?id='+id+'&temp='+Math.round(Math.random()*10000);
			$.dialog({
		        title: '故障信息查看',
		        content: 'url:'+ toUrl,
		        okVal: false,//确定按钮文字
		        cancelVal: false,//取消按钮文字
		        min: true, //是否显示最小化按钮
		        max: false,//是否显示最大化按钮
		        fixed: false,//开启静止定位
		        lock: true,//开启锁屏
		        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）
		        time: null,//设置对话框显示时间
		        resize: true,//是否允许用户调节尺寸
		        drag: true,//是否允许用户拖动位置
		        cache: false,//是否缓存iframe方式加载的窗口内容页
		        width: '500px',
		        height: 600
			});
			}
		//查询
		function gridSearch(){
			var CHEXING = $.trim(jQuery("#CHEXING").val());
            var ZIXITONG = $.trim(jQuery("#ZIXITONG").val()); 
            var LINGBUJIAN = $.trim(jQuery("#LINGBUJIAN").val());
            var SHIBIEHAO = $.trim(jQuery("#SHIBIEHAO").val());
            var GUZHANGFASHENGTIME = $.trim(jQuery("#GUZHANGFASHENGTIME").val());
            var ADDUSER = $.trim(jQuery("#ADDUSER").val());
            var GUZHANGNAME = $.trim(jQuery("#GUZHANGNAME").val());
            var LICHENG1 = $.trim(jQuery("#LICHENG1").val());
            var LICHENG2 = $.trim(jQuery("#LICHENG2").val());
            var GUZHANGDENGJI = $.trim(jQuery("#GUZHANGDENGJI").val());
            var params = {  
                        "CHEXING" : CHEXING,                           
                        "ZIXITONG" : ZIXITONG,
                        "LINGBUJIAN" : LINGBUJIAN,
                        "SHIBIEHAO":SHIBIEHAO,
                        "GUZHANGFASHENGTIME":GUZHANGFASHENGTIME,
                        "ADDUSER":encodeURIComponent(ADDUSER),
                        "GUZHANGNAME":encodeURIComponent(GUZHANGNAME),
                        "LICHENG1":LICHENG1,
                        "LICHENG2":LICHENG2,
                        "GUZHANGDENGJI":GUZHANGDENGJI
                         };
            var postData = $("#gridTable").jqGrid("getGridParam", "postData");
            $.extend(postData, params);
			jQuery("#gridTable").jqGrid('setGridParam',
			{
				url:'<%=request.getContextPath() %>/weituodan!queryGuzhangKuList.action'
			}).trigger("reloadGrid", [{page:1}]);
        } 
       
		//刷新
		function refreshIt(){
			//resetSearch();
			jQuery("#gridTable").jqGrid('setGridParam',
			{
				url:'<%=request.getContextPath() %>/gongyingshang!queryGongYingShang.action'
			}).trigger("reloadGrid", [{page:1}]);
		    
		}
		function reload(){
			refreshIt();
		}
		//清空
		function reset(){
			jQuery("#equipmentNo").val("");
			jQuery("#equipmentName").val("");
			jQuery("#equipmentType").val("");
			jQuery("#equipmentStandard").val("");	
			jQuery("#Manufacturer").val("");
			jQuery("#AssetType").val("");
			jQuery("#Station").val("");
			jQuery("#State").val("");
			jQuery("#inGroup").val("");
			jQuery("#CheckDate").val("");
			jQuery("#FactoryDate").val("");
		}
	        
	      //页面上的刷新按钮
			function shuaXin(){
				reset();
				gridSearch();
			}
		//参数信息：表明，关联列，显示列
	function selectData(id,tablename,colname,disname,cnname,fieldslist,formid){
	    var fileColname ='hideFileName';
	    if(tablename=='DIC_STANDARD'){
	      fileColname = "YCLJS_GYYW";
	    }
	    var   datas = window.showModalDialog("<%=request.getContextPath() %>/auto!chooseDatalist.action?byTableValueId=null&tablename="+tablename+"&colname="+colname+"&disname="+disname+"&cnname="+escape(encodeURIComponent(cnname))+"&fileColname="+fileColname+"&formid="+formid+"&fileName="+id+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=800px;dialogHeight=500px");
	       if(typeof(datas) == 'undefined'){
		   }else{
			 var json1 = eval('(' + datas + ')');
			 document.getElementById(id).value = json1.ID;
			
			 var disnamearray = disname.split(',');
			if(formid=='4424'){//整车可靠性试验流程  添加故障页面
				if(id=='FENLEI'){//车型
			 		document.getElementById("FENLEINAME").value = json1[disnamearray[0]];
			 	}else
			 	if(id=='CHEXING'){//车型
			 		document.getElementById("CHXINGNAME").value = json1[disnamearray[0]];
			 	}else if(id=='ZIXITONG'){//子系统
			 		document.getElementById("XITONGNAME").value = json1[disnamearray[0]];
			 	}else if(id=='LINGBUJIAN'){//零部件
			 		document.getElementById("LINGBUJIANNAME").value = json1[disnamearray[0]];
			 	}else if(id=='GUZHANGPATTERN'){//故障模式
			 		document.getElementById("GUZHANGPATTERNNAME").value = json1[disnamearray[0]];
			 	}
			 }
			 else{
			    document.getElementById("data_"+id).value = json1.NAME;
			   if (fieldslist!=undefined){
			 	var fieldslistarray = fieldslist.split(',');
			 	for(var i=0;i<fieldslistarray.length;i++){
			 		if (i==0){
			 			document.getElementById("data_"+id).value = json1[disnamearray[0]];
			 		}
			 		if(fieldslistarray[i] == "COUNT"){
			 			$('#COUNT').numberbox('setValue', json1[disnamearray[i]]);
			 		}else{
			 			document.getElementById(fieldslistarray[i]).value = json1[disnamearray[i]];
			 		}
			 	}
			   }
			   else{
			 	document.getElementById("data_"+id).value = json1[disnamearray[0]];
			   }
			}
			 
			 
		  }
	}
	//选择零部件
	function selectLBJ(){
		var   datas = window.showModalDialog("<%=request.getContextPath() %>/view/choose_lingbujian.jsp?flag=1&zixitongId=",'',"dialogWidth=800px;dialogHeight=500px");
		if(typeof(datas) == 'undefined'){
		}else{
			var json1 = eval('(' + datas + ')');
			 document.getElementById("LINGBUJIAN").value = json1.id;
			 document.getElementById("LINGBUJIANNAME").value = json1.name;
		}
	}
	//選擇子系統
	function selectZixitong(){
		
		var   datas = window.showModalDialog("<%=request.getContextPath() %>/view/choose_lingbujian.jsp?flag=0&zixitongId=",'',"dialogWidth=800px;dialogHeight=500px");
		if(typeof(datas) == 'undefined'){
		   }else{
			 var json1 = eval('(' + datas + ')');
			 document.getElementById("ZIXITONG").value = json1.id;
			 document.getElementById("XITONGNAME").value = json1.name;
		}
	}
	//导出excel
	function exportExcel(){
		var colNames = jQuery("#gridTable").jqGrid('getGridParam','colNames');
			var titleNames ="";
			var fieldsNames ="";
			for(var i=2;i<colNames.length;i++){
				titleNames+=colNames[i]+",";
			} 
			
			titleNames = encodeURIComponent(titleNames);
			var colModel = jQuery("#gridTable").jqGrid('getGridParam','colModel');
			for(var i=2;i<colModel.length;i++){
				fieldsNames+=colModel[i]["name"]+",";
			} 
			fieldsNames = encodeURIComponent(fieldsNames);
			$('#form1').attr("action","<%=request.getContextPath() %>/weituodan!exportExcel.action?titleNames="+titleNames+"&fieldsNames="+fieldsNames);
			$('#form1').submit();
	}
	      
	</script>	
	</head>
	<body>
	<form action="" method="post" id="form1">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
		   		<td>
			 		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="font12Black_B">
			   		<tr>
			        	<td width="6%" height="35">车型：</td>
			        	<td width="13%">
				        		<input type="hidden" id="CHEXING"  name="CHEXING" />
				  				<input type="text" readonly=readonly id="CHXINGNAME"   name="CHXINGNAME" style="width: 130px;"  value="" />
			  					<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" align="absmiddle" onclick="selectData('CHEXING','GWM_APPLICATIONMODE','ID','T_CHEXINGNAME','车型','null','4424')" />
						</td>
			        	<td width="9%" height="35" align="right">子系统：</td>
			        	<td width="13%">
			        		<input type="hidden" id="ZIXITONG"  name="ZIXITONG"/>
		  				    <input type="text" readonly=readonly id="XITONGNAME"   name="XITONGNAME" style="width: 130px;"  value="" />
		  				    <img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" style="cursor:hand; vertical-align: middle;" onclick="selectZixitong()" />
						</td>
			        	<td width="8%" height="35" align="right">零部件：</td>
			        	<td width="13%">
			        		<input type="hidden" id="LINGBUJIAN"  name="LINGBUJIAN" />
			  				<input type="text" readonly=readonly id="LINGBUJIANNAME"   name="LINGBUJIANNAME" style="width: 130px;"  value="" />
			  				<img src="<%=request.getContextPath() %>/web/images/form_icon_1.gif" style="cursor:hand; vertical-align: middle;" onclick="selectLBJ()" />
						</td>
			       	 	<td width="15%" align="center"><input type="button" name="button" id="button" value="查询" onclick="gridSearch()" class="search_Btn" />
			      			&nbsp;<input type="reset" name="button2" id="button2" value="清空" onclick="reset()" class="search_Btn" />
			      		</td>
			      	</tr>
			      	
			      </table>
			      <div id="panel" style="display:none;">
			      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="font12Black_B">
			      	<tr>
			      		<td width="6%" height="35">任务识别号：</td>
			        	<td width="13%">
			  				<input type="text" id="SHIBIEHAO"   name="SHIBIEHAO" style="width: 130px;"  value="" />
						</td>
						<td width="9%" height="35" align="right">故障发生时间：</td>
			        	<td width="13%">
			  				<input type="text" id="GUZHANGFASHENGTIME"   name="GUZHANGFASHENGTIME" onClick="WdatePicker()" style="width: 130px;"  value="" />
						</td>
						<td width="8%" height="35" align="right">记录人：</td>
			        	<td width="13%">
			  				<input type="text" id="ADDUSER"   name="ADDUSER" style="width: 130px;"  value="" />
						</td>
						<td width="15%" align="center">
			      			&nbsp;
			      		</td>
			      	</tr>
			      	<tr>
			      		<td width="6%" height="35">故障名称：</td>
			        	<td width="13%">
			  				<input type="text" id="GUZHANGNAME"   name="GUZHANGNAME" style="width: 130px;"  value="" />
						</td>
						<td width="9%" height="35" align="right">行驶里程：</td>
			        	<td width="13%">
			  				<input type="text" id="LICHENG1"   name="LICHENG1" style="width: 130px;"  value="" />
						</td>
						<td width="8%" height="35" align="center">至&nbsp;&nbsp;&nbsp;</td>
			        	<td width="13%">
			  				<input type="text" id="LICHENG2"   name="LICHENG2" style="width: 130px;"  value="" />
						</td>
						<td width="15%" align="center">
			      			&nbsp;
			      		</td>
			      	</tr>
			      	<tr>
			      		<td width="6%" height="35">故障等级：</td>
			        	<td width="13%">
			  				<select id="GUZHANGDENGJI" name="GUZHANGDENGJI"  style="width: 133px;"   >
			  					<option value="">请选择</option>
			  					<option value="A">A</option>
			  					<option value="B">B</option>
			  					<option value="C">C</option>
			  					<option value="D">D</option>
			  					<option value="E">E</option>
			  					<option value="F">F</option>
			  				</select>
						</td>
						<td width="9%" height="35" align="right"></td>
			        	<td width="13%"></td>
						<td width="8%" height="35" align="right"></td>
			        	<td width="13%"></td>
						<td width="15%" align="center">
			      			&nbsp;
			      		</td>
			      	</tr>
			      	
			    </table>
			    </div>		    
		  		</td>
		 	  </tr>
		      <tr>
                <td align="right" height="9" class="sclinebotBg"></td>
	          </tr>
		      <tr>
			    <td width="92%" align="right"><div class="btnStatus" id="flip"></div></td>
			    <td width="8%">&nbsp;</td>
			  </tr>
			</table>
			<table style="width: 100%;" class="tableCont">
				<tr>
					<td height="25" valign="top">
		         	<input id="add"    type='button' value='查 看' onclick="viewGuzhang()" class='button_b' />
		         	<input id="add"    type='button' value='导出excel' onclick="exportExcel()" class='button_b' />
		         	</td>
				</tr>
				<tr>
					<td colspan="4" style="padding-top:8px;">
						<table id="gridTable"></table>
						<div id="gridPager"></div>
					</td>
				</tr>
		   </table>
	</form>
	</body>
</html>
